home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
22
/
2
/
DISK2220.ZIP
/
SCREDIT2.EXE
/
VALIDATE.C
< prev
next >
Wrap
Text File
|
1990-12-23
|
14KB
|
666 lines
/* Turbo ScrEdit Validate Procedures */
void S_Find_Min_and_Max()
{
int C1, C2, s_len;
s_compmin[0]=0;
s_compmax[0]=0;
C1 = 0;
C2 = 0;
s_len=strlen(s_curstr);
s_min_max_loaded = 0;
s_endofline = 0;
while (!s_min_max_loaded)
{
s_sub++;
if (s_sub<s_len)
{
if (s_curstr[s_sub]==94)
{
s_sub++;
s_compmax[C2++]=s_curstr[s_sub];
}
else
{
if (s_curstr[s_sub]==39)
{
if (s_compmax[0]==0) strcpy(s_compmax,s_compmin);
s_min_max_loaded = 1;
}
else
{
if (s_compmax[0]==0)
{
s_compmin[C1++]=s_curstr[s_sub];
s_compmin[C1]=0;
}
else
{
s_compmax[C2++]=s_curstr[s_sub];
s_compmax[C2]=0;
}
}
}
if ((s_compmin[0]==92)||(s_compmin[0]==61)) s_min_max_loaded = 1;
}
else
{
s_min_max_loaded=1;
s_endofline =1;
}
}
if (s_upcase)
{
strcpy(s_compmin,strupr(s_compmin));
strcpy(s_compmax,strupr(s_compmax));
}
}
void S_ReadNextRangeRec()
{
unsigned int Y;
long rec;
s_currline = s_nextline;
if (s_vrec != s_nextrec)
{
rec = (long) (s_nextrec)*sizeof(*s_indx);
fseek(s_file,rec,0);
fread(s_indx,sizeof(*s_indx),1,s_file);
s_vrec = s_nextrec;
}
s_nextrec = s_indx->D.s_rangerec [s_currline];
s_nextline = s_indx->D.s_rangeline[s_currline]-1;
Y = s_indx->D.s_rangelist[s_currline][0];
setmem(&s_indx->D.s_rangelist[s_currline][Y+1],78-Y,0);
movmem(&s_indx->D.s_rangelist[s_currline][1],&s_curstr,
s_indx->D.s_rangelist[s_currline][0]+1);
s_sub = (s_insideif) ? 4:1;
s_compmin[0]=0;
s_compmax[0]=0;
}
void S_ProcessDate()
{
char
DateMask[40],
TestMonth[3],
TestDay[3],
TestYear[5],
CheckMonth,
CheckDay,
CheckYear;
int
x,y,z,
WorkMonth,
WorkDay,
WorkYear,
WorkNum;
CheckMonth = 0;
CheckDay = 0;
CheckYear = 0;
WorkMonth = 0;
WorkDay = 0;
WorkYear = 0;
s_errormsg[0] = 0;
x = (s_insideif) ? 8:5;
z = x;
y = 0;
while (s_curstr[x]!=0)
{
switch (s_curstr[x])
{
case 'D':
{
if (!isdigit(s_editstr[y]))
{
strcpy(s_errormsg,"Day contains a invalid character for <");
strcat(s_errormsg,(char *)&s_curstr[z]);
strcat(s_errormsg,"> Format");
goto Exit_Point;
}
CheckDay++;
TestDay[CheckDay-1]=s_editstr[y];
TestDay[CheckDay] =0;
break;
}
case 'M':
{
if (!isdigit(s_editstr[y]))
{
strcpy(s_errormsg,"Month contains a invalid character for <");
strcat(s_errormsg,(char *)&s_curstr[z]);
strcat(s_errormsg,"> Format");
goto Exit_Point;
}
CheckMonth++;
TestMonth[CheckMonth-1]=s_editstr[y];
TestMonth[CheckMonth] =0;
break;
}
case 'Y':
{
if (!isdigit(s_editstr[y]))
{
strcpy(s_errormsg,"Year contains a invalid character for <");
strcat(s_errormsg,(char *)&s_curstr[z]);
strcat(s_errormsg,"> Format");
goto Exit_Point;
}
CheckYear++;
TestYear[CheckYear-1]=s_editstr[y];
TestYear[CheckYear] =0;
break;
}
default :
{
if (s_editstr[y]!=s_curstr[x])
{
strcpy(s_errormsg,"Please enter date in <");
strcat(s_errormsg,(char *)&s_curstr[z]);
strcat(s_errormsg,"> Format");
goto Exit_Point;
}
}
}
y++;
x++;
}
if (s_editstr[y]!=0)
{
strcpy(s_errormsg,"You have keyed to many charactes for <");
strcat(s_errormsg,(char *)&s_curstr[z]);
strcat(s_errormsg,"> Format");
goto Exit_Point;
}
WorkDay = (CheckDay >0) ? atoi(TestDay) :0;
WorkMonth = (CheckMonth>0) ? atoi(TestMonth):0;
WorkYear = (CheckYear >0) ? atoi(TestYear) :0;
WorkNum = (WorkYear/4);
WorkNum *= 4;
WorkNum -= WorkYear;
if ((CheckMonth>0)&&((WorkMonth < 1)||(WorkMonth>12)))
{
strcpy(s_errormsg,"You have keyed a invalid Month. Use 1 thru 12 only");
goto Exit_Point;
}
if (CheckDay>0)
{
if ((WorkMonth==4)||(WorkMonth==6)||(WorkMonth==9)||(WorkMonth==11))
{
if (WorkDay>30)
{
strcpy(s_errormsg,"This month can have only 30 days or less");
goto Exit_Point;
}
}
else
{
if ((WorkMonth!=2)&&(WorkDay>31))
{
strcpy(s_errormsg,"This month can have only 31 days or less");
goto Exit_Point;
}
else
{
if (WorkMonth == 2)
{
if (WorkNum==0)
{
if (WorkDay>29)
{
strcpy(s_errormsg,"February can have only 29 days or less");
goto Exit_Point;
}
}
else
{
if (WorkDay>28)
{
strcpy(s_errormsg,"February can have only 28 days or less");
goto Exit_Point;
}
}
}
}
}
}
if ((CheckYear>0)&&(WorkYear<1))
{
strcpy(s_errormsg,"Year must have a value greater than zero.");
goto Exit_Point;
}
Exit_Point:
if (s_errormsg[0]!=0)
{
s_screenvalid = 0;
s_validate_finished = 1;
s_skip = 1;
}
}
void S_ProcessIn()
{
int x,y,z;
s_getfieldtype(s_field->C.s_type[s_point]);
s_decimal = s_ftype;
s_matched = 0;
s_compmin[0] = 0;
if (!s_matched)
{
while ((!s_matched)&&(s_compmin[0]!=92)&&(s_compmin[0]!='='))
{
S_Find_Min_and_Max();
if ((s_compmin[0]!=92)&&(s_compmin[0]!='=')&&(!s_endofline))
{
if (s_decimal < 8)
{
s_numeric = atof(s_editstr);
s_compmin_Numeric = atof(s_compmin);
s_compmax_Numeric = atof(s_compmax);
if ((s_numeric>=s_compmin_Numeric)&&(s_numeric<=s_compmax_Numeric))
s_matched = 1;
}
else
{
if ((strcmp(s_editstr,s_compmin)>=0) &&
(strcmp(s_editstr,s_compmax)<=0))
s_matched = 1;
}
}
if ((s_endofline) && ((s_compmin[0]==0) && (s_compmax[0]==0)))
{
S_ReadNextRangeRec();
while ((s_curstr[s_sub]!=39)&&
(s_curstr[s_sub]!=92)&&
(s_curstr[s_sub++]!='='));
if ((s_curstr[s_sub]==92)||(s_curstr[s_sub]=='='))
{
s_compmin[0]=s_curstr[s_sub];
s_compmin[1]=0;
}
}
}
}
if (s_matched)
{
while ((s_curstr[s_sub]!=92)&&(s_curstr[s_sub]!='='))
{
s_sub=0;
while ((s_curstr[s_sub]!=0)&&
(s_curstr[s_sub]!=92)&&
(s_curstr[s_sub]!='=')) s_sub++;
if ((s_curstr[s_sub]!=92)&&(s_curstr[s_sub]!='='))
{
S_ReadNextRangeRec();
s_sub=0;
}
}
if (s_curstr[s_sub]=='=')
{
s_screenvalid = 0;
s_validate_finished = 1;
strcpy(s_errormsg,(char *)&s_curstr[s_sub+1]);
}
else
{
s_opcode[0]=0;
s_matched = 0;
}
}
else
{
if (s_curstr[s_sub]==92)
{
s_screenvalid = 0;
s_validate_finished = 1;
strcpy(s_errormsg,(char *)&s_curstr[s_sub+1]);
}
else
s_opcode[0]=0;
}
}
void S_Processif()
{
int c,x,y,z;
s_matched = 0;
s_compmin[0]=0;
s_compmax[0]=0;
s_endofline =0;
while (strcmp(s_compmin,"THEN")!=0)
{
if (s_endofline)
{
S_ReadNextRangeRec();
s_sub=0;
while ((s_curstr[s_sub]!=0)&&(s_curstr[s_sub]!=39)) s_sub++;
}
if (s_curstr[3]=='N')
{
x = 7;
s_opcode1[0]='N';
}
else
{
x = 3;
s_opcode1[0]=0;
}
y=0;
while (x>0)
{
if ((s_curstr[x]!=39)&&(s_curstr[x]!=32)) s_compfield[y++]=s_curstr[x++];
else x=0;
s_compfield[y]=0;
}
strupr(s_compfield);
s_fieldnum = 0;
x = 1;
while (x)
{
if (s_fieldnum == s_curr.s_count)
{
s_fieldnum = -1;
x = 0;
}
else
if (strcmp(s_compfield,strupr(s_field->C.s_fieldname[s_fieldnum]))==0)
x=0;
else
s_fieldnum++;
}
s_compmin[0]=0;
s_compmax[0]=0;
if (s_fieldnum > -1) S_Get_Field_Value(s_fieldnum);
else strcpy(s_compmin,"THEN");
if (s_upcase) strupr(s_editstr);
s_getfieldtype(s_field->C.s_type[s_fieldnum]);
s_decimal = s_ftype;
s_endofline = 0;
while ((strcmp(s_compmin,"AND")!=0)&&
(strcmp(s_compmin,"OR")!=0)&&
(strcmp(s_compmin,"THEN")!=0))
{
if (s_endofline)
{
S_ReadNextRangeRec();
s_sub=0;
while ((s_curstr[s_sub]!=0)&&(s_curstr[s_sub]!=39)) s_sub++;
}
S_Find_Min_and_Max();
if ((strcmp(s_compmin,"AND")!=0)&&
(strcmp(s_compmin,"OR")!=0) &&
(strcmp(s_compmin,"THEN")!=0))
{
if (s_decimal<7)
{
s_numeric = atof(s_editstr);
s_compmin_Numeric = atof(s_compmin);
s_compmax_Numeric = atof(s_compmax);
if (s_opcode1[0]=='N')
{
if ((s_numeric<s_compmin_Numeric)||(s_numeric>s_compmax_Numeric))
s_matched = 1;
}
else
{
if ((s_numeric>=s_compmin_Numeric)&&(s_numeric<=s_compmax_Numeric))
s_matched = 1;
}
}
else
{
if (s_opcode1[0]=='N')
{
if ((strcmp(s_editstr,s_compmin)<0)||(strcmp(s_editstr,s_compmax)>0))
s_matched = 1;
}
else
if ((strcmp(s_editstr,s_compmin)>=0)&&
(strcmp(s_editstr,s_compmax)<=0))
s_matched = 1;
}
}
}
if (strcmp(s_compmin,"AND")==0)
{
if (!s_matched)
{
s_compmin[0]=0;
while ((strcmp(s_compmin,"OR")!=0)&&(strcmp(s_compmin,"THEN")!=0))
{
S_ReadNextRangeRec();
s_sub=0;
while ((s_curstr[s_sub]!=0)&&(s_curstr[s_sub]!=39)) s_sub++;
s_compmin[0]=0;
while ((strcmp(s_compmin,"AND")!=0)
&&(strcmp(s_compmin,"OR")!=0)
&&(strcmp(s_compmin,"THEN")!=0))
S_Find_Min_and_Max();
}
if (strcmp(s_compmin,"OR")==0) s_compmin[0]=0;
}
else
{
s_compmin[0] = 0;
s_matched = 0;
}
}
else
{
if (strcmp(s_compmin,"OR")==0)
{
if (s_matched)
{
while (strcmp(s_compmin,"THEN")!=0)
{
S_ReadNextRangeRec();
s_sub=0;
while ((s_curstr[s_sub]!=0)&&(s_curstr[s_sub]!=39)) s_sub++;
while ((strcmp(s_compmin,"AND")!=0)
&&(strcmp(s_compmin,"OR")!=0)
&&(strcmp(s_compmin,"THEN")!=0))
S_Find_Min_and_Max();
}
}
else
s_compmin[0]=0;
}
}
}
strcpy(s_editstr,s_editstrhold);
if (s_matched)
{
s_matched = 0;
s_insideif = 1;
while ((s_screenvalid)&&(s_curstr[0]!='E')&&(!s_skip))
{
S_ReadNextRangeRec();
if (s_curstr[0]!='E')
{
switch (s_curstr[3])
{
case 'D' : {S_ProcessDate();break;}
case 'I' :
{
s_sub=0;
while ((s_curstr[s_sub]!=0)&& (s_curstr[s_sub]!=39)) s_sub++;
S_ProcessIn();
break;
}
case 'S' : {s_skip = 1;break;}
case 'E' :
{
s_screenvalid = 0;
strcpy(s_errormsg,&s_curstr[9]);
}
}
}
}
s_insideif = 0;
}
while (strcmp(s_curstr,"ENDIF")!=0) S_ReadNextRangeRec();
}
void s_validate_Location()
{
int x,y,z;
s_upcase= 0;
s_insideif= 0;
s_matched= 0;
s_skip= 0;
s_opcode[0]= 0;
s_currline= 9999;
while ((s_nextrec)&&(!s_skip))
{
S_ReadNextRangeRec();
if (s_curstr[0] == 'I') /* check for IN or if */
{
s_sub = s_pos(s_curstr,"'");
if (s_curstr[1] == 'F') S_Processif();
else S_ProcessIn();
if (s_validate_finished) s_nextrec = 0;
}
if (s_curstr[0] == 'U') /* check for Upshift key word */
{
if (s_curstr[10] == 'N') /* if ON */
{
s_upcase = 1;
strupr(s_editstr);
}
else
{
s_upcase = 0; /* if Off */
strcpy(s_editstr,s_newstr);
}
strcpy(s_editstrhold,s_editstr);
}
if ((s_curstr[0] == 'R')||((s_curstr[0] == 'S')&&(s_curstr[1] == 'K')))
{
x = strlen(s_editstr);
while ((x>0)&&(s_editstr[x-1]<33))
{
s_editstr[x-1]=0;
x++;
}
if (s_editstr[0]==0)
{
if (s_curstr[0]=='S') s_nextrec = 0;
if (s_curstr[0]=='R')
{
s_sub = 0;
while ((s_curstr[s_sub]!=0)&&(s_curstr[s_sub]!=39)) s_sub++;
if (s_curstr[s_sub]==39)
strcpy(s_errormsg,(char *)&s_curstr[s_sub]);
else
strcpy(s_errormsg,"** This field is required **");
s_screenvalid = 0;
s_nextrec = 0;
}
}
}
if (s_curstr[0]=='D') S_ProcessDate();
}
}
void s_validatescreen()
{
int C;
s_prevfield = s_point;
if (s_curr.s_rangerecno==0)
{
s_validate_finished = 1;
s_screenvalid = 1;
}
else
{
s_point = -1;
s_upcase = 0;
s_validate_finished = 0;
if (s_validatefield > -1) s_point = s_validatefield;
}
while (s_validate_finished==0)
{
if (s_point < s_curr.s_count)
{
s_point++;
s_nextrec = s_field->C.s_rangenextrec [s_point];
s_nextline = s_field->C.s_rangenextline[s_point]-1;
if (s_nextrec)
{
s_screenvalid = 1;
S_Get_Field_Value(s_point);
strcpy(s_editstrhold,s_editstr);
strcpy(s_newstr,s_editstr);
s_validate_Location();
if ((!s_screenvalid)||(s_validatefield > -1))
{
s_validate_finished = 1;
s_point--;
}
}
}
else
{
s_validate_finished = 1;
}
}
if (s_screenvalid)
s_point = s_prevfield;
else
if (s_isdupe(s_point)) s_setdupefields = 1;
s_validatefield = -1;
}